package com.atguigu.schedule.dao.impl;

import com.atguigu.schedule.dao.BaseDao;
import com.atguigu.schedule.dao.SysUserDao;
import com.atguigu.schedule.pojo.SysUser;

import java.util.List;

public class SysUserDaoImpl extends BaseDao implements SysUserDao {
    @Override
    public int addSysUser(SysUser sysUser) {

        String sql = "insert into sys_user values(DEFAULT,?,?)";

        int rows = baseUpdate(sql, sysUser.getUsername(), sysUser.getUserPwd());

        return rows;
    }

    @Override
    public SysUser findByUserName(String username) {
        String sql = "select uid,username,user_pwd as userPwd from sys_user where username = ?";
        List<Object> sysUserList = baseQuery(SysUser.class, sql, username);
        if(sysUserList != null && sysUserList.size() > 0){
            SysUser sysUser = (SysUser) sysUserList.get(0);
            return sysUser;
        }

        return null;
    }
}
